package com.whynot.frame.basic.util;

import java.io.*;


public class Tools {
	
	//序列化
	public static byte [] serialize(Object obj){
		if(obj==null){
			return null;
		}
		ObjectOutputStream obi=null;
		ByteArrayOutputStream bai=null;
		try {
			bai=new ByteArrayOutputStream();
			obi=new ObjectOutputStream(bai);
			obi.writeObject(obj);
			byte[] byt=bai.toByteArray();
			return byt;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	//反序列化
	public static Object unserizlize(byte[] byt){
		if(byt==null){
			return null;
		}
		ObjectInputStream oii=null;
		ByteArrayInputStream bis=null;
		bis=new ByteArrayInputStream(byt);
		try {
			oii=new ObjectInputStream(bis);
			Object obj=oii.readObject();
			return obj;
		} catch (Exception e) {

			e.printStackTrace();
		}
		return null;
	}
}
